home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstdio.arc / SRC.ARC / GETENV.A < prev    next >
Text File  |  1985-08-15  |  1KB  |  73 lines

  1. ;    getenv.a - get environment string.
  2. ;    (C) Copyright 1985 Cray Research Inc. - All Rights Reserved.
  3. ;    G. R. Mansfield.  85/08/15.
  4. ;    Ver 1.0-5815.
  5.  
  6.  
  7.     dseg
  8.     public    _pfb
  9.  
  10. l_ebf    equ    80        ; environment string buffer
  11. ebf    rb    l_ebf
  12.  
  13.     cseg
  14.     public    getenv_
  15.  
  16.  
  17. ;    char *getenv(name)
  18. ;    char *name;
  19.  
  20. getenv_:
  21.     mov    bx,sp        ; requested string
  22.     mov    si,[bx+2]    ; toupper requested string to local string
  23.     mov    cx,l_ebf
  24.     mov    dx,cx
  25.     mov    bx,offset ebf
  26.     mov    di,bx
  27. gev1:    lodsb            ; check character
  28.     or    al,al
  29.     jz    gev3        ; if end of string
  30.     cmp    al,'a'
  31.     jl    gev2        ; if not lower case
  32.     cmp    al,'z'
  33.     jg    gev2
  34.     sub    al,'a'-'A'
  35. gev2:    stosb
  36.     loop    gev1
  37.     xor    ax,ax        ; return NULL if string too long
  38.     ret
  39.  
  40. gev3:    mov    al,'='        ; add '=' for environ search
  41.     stosb
  42.     sub    dx,cx        ; set string length
  43.     inc    dx
  44.  
  45.     push    ds
  46.     mov    ax,_pfb        ; set start of environ strings
  47.     mov    ds,ax
  48.     mov    ds,[02Ch]
  49.     xor    si,si
  50.     mov    ah,0        ; upper part of NULL for return
  51. gev4:    mov    al,[si]        ; check next string
  52.     or    al,al
  53.     jz    gev8        ; null string = end of strings
  54.     mov    cx,dx        ; compare strings
  55.     mov    di,bx
  56.     repz cmpsb
  57.     jz    gev6        ; if match found
  58.     mov    cx,-1        ; skip to end of environ string
  59. gev5:    lodsb
  60.     or    al,al
  61.     loopnz    gev5
  62.     jmp    gev4        ; next string
  63.  
  64. gev6:    mov    cx,l_ebf-1    ; copy string
  65.     mov    di,bx
  66. gev7:    lodsb
  67.     stosb
  68.     or    al,al
  69.     loopnz    gev7
  70.     mov    ax,offset ebf    ; return pointer to string
  71. gev8:    pop    ds
  72.     ret
  73.